<?php
// +----------------------------------------------------------------------
// | flow-notify / Sms.php    [ 2021/11/9 10:29 上午 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2021 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);


namespace notify;


class Sms extends Service
{
    /**
     * 短信驱动名称
     * @var null
     */
    protected $driver = null;

    protected $config = [];

    function __construct(string $driverName, array $config)
    {
        $this->driver = ucfirst($driverName);
        $this->config = $config;
    }

    /**
     * 获取短信发送驱动
     * @return mixed
     * @throws \Exception
     */
    protected function getDriver(){
        $obj = '\\notify\\sms\\'.$this->driver;
        return self::getInstance($obj, [$this->config]);
    }

    /**
     * 发送短信
     * @param string $phone
     * @param string $msg
     * @return mixed
     * @throws \Exception
     */
    public function send(string $phone, string $msg){
        return $this->getDriver()->send($phone, $msg);
    }

    /**
     * 查询余额
     * @return mixed
     * @throws \Exception
     */
    public function getBalance(){
        return $this->getDriver()->balance();
    }

}